<?php
/**
 * [LupMisNotAllowedSync]
 * 本代码为系统自动生成代码，请根据自己业务进行修改;
 * 生成时间 2022-02-15 20:59:18;
 * 版权所有 2020-2022 lizhongwen，并保留所有权利;
 * 说明: 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；不允许对程序代码以任何形式任何目的的再发布;
 * 作者: 中文Lee;
 * 作者主页: http://www.lizhongwen.com;
 * 邮箱: 360811363@qq.com;
 * QQ: 360811363;
 */

namespace modules\sys\controller;

use application\core\Lib;
use application\core\Request;
use application\core\Result;
use application\core\VerificationCode;
use Exception;
use modules\sys\service\impl\AccountServiceImpl;

class LoginController
{

    private $accountService;

    public function __construct()
    {
        $this->accountService = new AccountServiceImpl();
    }

    /**
     * 不校验token
     * @lupCheckToken false
     * @return array
     */
    public function login(): array
    {
        try {
            $login = $this->accountService->login(Request::json());
            return Result::success(true, $login, "登录成功");
        } catch (Exception $e) {
            return Result::fail(true, [], $e->getMessage());
        }
    }

    /**
     * 不校验token
     * @lupCheckToken false
     * @return array
     */
    public function getVerifyCode(): array
    {
        $verifyCodeToken = Request::json()['verify_code_token'];
        $res['verify_code_token'] = !empty($verifyCodeToken) ? $verifyCodeToken : "verify_code_token_" . Lib::generateUUIDv4();
        $res['redis_enable'] = REDIS_ENABLE;
        $res['verify_code'] = (new VerificationCode)->getCode($res['verify_code_token']);
        return Result::success(false, $res);
    }
}

